// https://leetcode-cn.com/problems/convert-bst-to-greater-tree/
// 538. Convert BST to Greater Tree

import { TreeNode } from '../utils/index.ts';

function convertBST(root: TreeNode | null): TreeNode | null {
    let sum = 0;
    function helper(root: TreeNode | null): void {
        if (root !== null) {
            helper(root.right);
            sum += root.val;
            root.val = sum;
            helper(root.left);
        }
    }

    helper(root);
    return root;
}
